<?php

namespace Encore\MediaManagerSelect;

use Encore\Admin\Form;
use Illuminate\Support\ServiceProvider;

class MediaManagerSelectServiceProvider extends ServiceProvider
{
    /**
     * {@inheritdoc}
     */
    public function boot(Extension $extension)
    {
        if (!Extension::boot()) {
            return;
        }

        if ($views = $extension->views()) {
            $this->loadViewsFrom($views, 'media-manager-select');
        }

        if ($this->app->runningInConsole() && $assets = $extension->assets()) {
            $this->publishes(
                [$assets => public_path('vendor/laravel-admin-ext/media-manager-select')],
                'media-manager-select'
            );
        }

        $this->app->booted(function () {
            Form::extend('mediaManagerSelect', MediaManagerSelect::class);
            Extension::routes(__DIR__.'/../routes/web.php');
        });
    }
}
